#include "group.h"
#include "main.h"


group::group(int t0,  int ll0, int lu0, real m0): type(t0), mass(m0), ll(ll0), lu(lu0)
{
    num = lu - ll + 1;
    if(type == 2) a.resize(num, atom_wall);     
    else    a.resize(num, atom_fluid);  
    
    FOR_EACH_ATOM_i
        a[i] = atom(type, ll+i, mass, R[ll+i]);

}


void group::r1_random(){
    
    vec3 ranvec;
    
    FOR_EACH_ATOM_i {
        ranvec.x = real(rand())/RAND_MAX;
        ranvec.y = real(rand())/RAND_MAX;
        ranvec.z = real(rand())/RAND_MAX;
        a[i].r1 = ranvec;
	}

}

void group::predict(){

    FOR_EACH_ATOM_i
        a[i].predict();

}

void group::correct(){

    FOR_EACH_ATOM_i
        a[i].correct();

}

void group::binning(){

    FOR_EACH_ATOM_i
	    a[i].binning();

}

void group::tether(){

    FOR_EACH_ATOM_i
	    a[i].tether();

}

void group::periodicbc(){

    if( PDX ){
	    for (int i=0; i<num; i++) {
		    a[i].periodicx();
	    };
    }
    if( PDY ){
	    for (int i=0; i<num; i++) {
		    a[i].periodicy();
	    };
    }
    if( PDZ ){
	    for (int i=0; i<num; i++) {
		    a[i].periodicz();
	    };
    }	
}

void group::addforce(vec3 force){
	
    FOR_EACH_ATOM_i
	    a[i].addforce(f[i]);

}

void group::clearforce(){
	
    FOR_EACH_ATOM_i
        a[i].clearforce();
 
}


void group::info()
{
    cout<<"-------------------Group Info--------------------"<<endl;
    cout<<"|\tGroup Type    |  "<<type<<endl;
    cout<<"|\tAtom Number   |  "<<num<<endl;
    cout<<"|\tID Range      |  "<<ll<<"-"<<lu<<endl;
    cout<<"-------------------------------------------------"<<endl;

}
